Add compiled outputs data for bundle, buildStatic methods#693
Add compiled outputs data for bundle, buildStatic methods#693sergei-startsev wants to merge 1 commit intosystemjs:masterfrom
bundle, buildStatic methods#693Conversation
a49584b to
2649e18
Compare
|
Thanks, I like the idea. How can the outputs object be used after being modified though? Can you provide an example of the sort of API you see this being used with? |
|
Here is how it could be used for building return builder.buildStatic(url, {options}).then(function (output) {
//resulted eval bundle with inline sourceMaps
var bundle = "";
output.outputs.forEach(function (el) {
bundle += `
eval("${JSON.stringify(el.source)}\n
//# sourceMappingURL=data:application/json;base64,${new Buffer(el.sourceMaps).toString("base64")}"
)\n`;
});
return bundle;
});another example uses the custom algorithm for concatenation sourcemaps: return builder.buildStatic(url, {options}).then(function (output) {
//maps output to the expected format
var files = output.outputs.map(function (el) {
if (el.source) {
//fixes source urls
el.sourceMap.sources = el.sourceMap.sources.map(function (sourceURL) {
return sourceURL.replace(/\\/g, "/");
});
return {
code: el.source,
map: el.sourceMap
};
} else {
return {
code: el,
map: undefined
};
}
});
//builds concatenated bundle with inline sourcemaps
var concatenated = concat(files, { delimiter: "\n" }).toStringWithSourceMap();
var bundle = `${concatenated.code}\n
//# sourceMappingURL=data:application/json;base64,${new Buffer(concatenated.map.toString()).toString("base64")}`;
return bundle;
});The idea is that you could customize your output bundle based on data in |
|
I think it would be better to accept an outputs hook as a build option something like: builder.bundle('x', {
hook: {
output: (outputs) => {
return modifiedOutputs;
}
}
}).then(...);That said, i'm weary to rush into a hook architecture on a whim without fully thinking it through as well. |
|
Could this pull request relate to my questions here about a static build with the semantics of |
0171134 to
52ad54c
Compare
I've added the additional field

outputsto the output ofbundle,buildStaticmethods. The field contains a sorted array of sources and appropriate source map data before merging them to the single bundle:It allows to add plugins that can build custom bundles based on provided data, e.g.
evalbundle:Here are more examples of different bundles that Webpack uses: devtool